﻿import com.dmotiko.general.BaseClip;
import com.dmotiko.general.ButtonClip;
import com.dmotiko.util.StringUtils;
import com.dmotiko.prune.*;
import flash.display.BitmapData;
import mx.transitions.easing.Strong;
import mx.transitions.Tween;
/**
 * ...
 * @author sminutoli
 */
class com.dmotiko.prune.NewItem
extends BaseClip
{
	private var mcContent:MovieClip;
	private var mcPhoto:MovieClip;
	private var mcl:MovieClipLoader;
		
	private function initClip():Void {
		mcl = new MovieClipLoader();
		mcl.addListener(this);
		bShowed = false;
		
		mcContent._visible = 
		mcPhoto._visible = false;
		
		mcContent._alpha =
		mcPhoto._alpha = 0;
		
	}
	
	public function show():Void {
		mcContent._visible = mcPhoto._visible = true;
		registerTween( "contentAppear", new Tween( mcContent, "_alpha", Strong.easeIn, 0, 100, 0.5, true), false, true );
		registerTween( "photoAppear", new Tween( mcPhoto, "_alpha", Strong.easeIn, 0, 100, 0.5, true), false, true );
	}
	
	private function tweenFinished( key:String, tween:Tween):Void {
		if ( key == "contentAppear" ) {
			tween.obj.aTransform = [ 100, 30, 30, 100, 100, 30, 30, 100 ];
			tween.obj.nTransform = 0;
			tween.obj.onEnterFrame = function() {
				if ( this.nTransform == this.aTransform.length ) {
					delete this.onEnterFrame;
					return;
				}
				this._alpha = this.aTransform[ this.nTransform ];
				this.nTransform++;
			}
			
		
		} else if ( key == "photoAppear" ) {
			tween.obj.aTransform = [ 100, 30, 30, 100 ];
			tween.obj.nTransform = 0;
			tween.obj.onEnterFrame = function() {
				if ( this.nTransform == this.aTransform.length ) {
					delete this.onEnterFrame;
					this._parent.showEnd();
					return;
				}
				this._alpha = this.aTransform[ this.nTransform ];
				this.nTransform++;
			}
		}
	}
	
	private function onLoadInit(target:MovieClip):Void {
		mcPhoto.bitmap = mcPhoto.createEmptyMovieClip("bitmap", mcPhoto.getNextHighestDepth());
		mcPhoto.bitmap._x = target._x;
		mcPhoto.bitmap._y = 20;
		target._visible = false;
		
        var bitmap:BitmapData = new BitmapData(
            target._width, 
            target._height, 
            true);

         mcPhoto.bitmap.attachBitmap(
            bitmap, 
            1,
            "auto", 
            true);

         bitmap.draw(target);
		 mcPhoto.bitmap._width = 276;
		 mcPhoto.bitmap._height = 170; 
	}
	
	private function refreshData():Void {
		var _data = data;
		if ( !data.doc ) {
			mcContent.mcDoc._alpha = 30;
			mcContent.mcDoc.enabled = false;
		} else {
			mcContent.mcDoc.enabled = true;
			mcContent.mcDoc.onRelease = function() {
				
				getURL( _data.doc, "_blank" );
			}
		}
		
		if ( !data.href ) {
			mcContent.mcLink._alpha = 30;
			mcContent.mcLink.enabled = false;
		} else {
			mcContent.mcLink.enabled = true;
			mcContent.mcLink.onRelease = function() {
				
				if ( SiteSections.validate(_data.href) ) Site.getApp().setSection( _data.href );
				else getURL( _data.href, "_blank" );
			}
		}
		
		mcContent.txtTitle.text = data.date+" "+data.title;
		mcContent.txtContent.text = data.content;
		mcl.loadClip(data.src, mcPhoto.img);
		
	}
	
}